package com.zhangyue.web.control;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.generator.TableMeta;
import com.zhangyue.core.annotation.RouteBind;
import com.zhangyue.web.model.User;
import com.zhangyue.web.service.UserService;

@RouteBind(path = "/user")
public class UserControl extends Controller{

public static final int PAGE_SIZE = 5;

static UserService service = UserService.userService;

public void add(){
service.add(getModel(User.class));
list();
}

public void list(){
Page<User> page = service.paginate(getParaToInt("p",1),PAGE_SIZE);
    setAttr("page",page);
    render("user_list.html");
    }

    public void toAddHtml(){
    render("user_add.html");
    }

    public void update(){
    service.update(getModel(User.class));
    list();
    }

    public void delete(){
    service.delete(getParaToInt("id"));
    list();
    }

    public void findById(){
    int id = getParaToInt("id");
    User user = service.findById(id);
    setAttr("user",user);
    render("user_update.html");
    }

    }